package com.niiwoo.civet.trade.report.upload.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import com.niiwoo.civet.trade.report.upload.util.encoders.Base64Encoder;
import sun.misc.BASE64Decoder;


/**
 * 
 * @author wanglei02
 *
 */
public class Base64Util {
	
	/**
	 *   
	 * @param data
	 * @return
	 */
	public String BJS_EncodeBase64(byte[] data)	{
		OutputStream out = new ByteArrayOutputStream();
		Base64Encoder base64En = new Base64Encoder();
		try {
			base64En.encode(data, 0, data.length, out);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return out.toString();
	}
	/**
	 * 
	 * @param data
	 * @return
	 */
	public byte[] BJS_DecodeBase64(String data)
	{
		 byte[] bData = null;

		    BASE64Decoder oDecoder = new BASE64Decoder();
		    try {
		      bData = oDecoder.decodeBuffer(data);
		    } catch (Exception e) {
		      bData = null;
		    }
		    return bData;
		
	}
}
